GSP_DIR =  ../../../../dep
LIB_DIR =  $(GSP_DIR)/sqlparser/lib
BUILD_DIR = .
CORE_DIR = $(GSP_DIR)/sqlparser/core
COLLECTION_DIR = $(GSP_DIR)/sqlparser/ext/collection
EXPRTRAVERSE_DIR = $(GSP_DIR)/sqlparser/ext/expr_traverse
NODEVISITOR_DIR = $(GSP_DIR)/sqlparser/ext/node_visitor
MODIFYSQL_DIR = $(GSP_DIR)/sqlparser/ext/modifysql
GSP_CORE_LIB = gspcore
GSP_COLLECTION_LIB = gspcollection

CC = gcc
CFLAGS = -c -g -I $(COLLECTION_DIR)/includes -I $(EXPRTRAVERSE_DIR) -I $(CORE_DIR) -I $(NODEVISITOR_DIR) 


DEMO_EXE = $(BUILD_DIR)/analyzescript

SOURCE = $(BUILD_DIR)/analyzescript.c \
	$(EXPRTRAVERSE_DIR)/expr_traverse.c \
	$(NODEVISITOR_DIR)/node_visitor.c \
	$(MODIFYSQL_DIR)/modifysql.c 

OBJECTS = $(BUILD_DIR)/analyzescript.o \
	$(BUILD_DIR)/expr_traverse.o \
	$(BUILD_DIR)/node_visitor.o \
	$(BUILD_DIR)/modifysql.o 

all: $(DEMO_EXE)

$(DEMO_EXE): create_build_dir \
	$(OBJECTS) \
	create_demo_exe 
	
create_demo_exe:
	$(CC)  $(OBJECTS)  -L$(LIB_DIR) -l$(GSP_CORE_LIB) -l$(GSP_COLLECTION_LIB) -o $(DEMO_EXE)
	rm -f $(BUILD_DIR)/*.o 
	
create_build_dir:
	@if [ ! -d "$(BUILD_DIR)" ]; \
	then \
	    mkdir $(BUILD_DIR); \
	fi \
	 	
$(BUILD_DIR)/analyzescript.o: $(BUILD_DIR)/analyzescript.c
	$(CC) $(CFLAGS) $< -o $@
	
$(BUILD_DIR)/expr_traverse.o: $(EXPRTRAVERSE_DIR)/expr_traverse.c
	$(CC) $(CFLAGS) $< -o $@

$(BUILD_DIR)/node_visitor.o: $(NODEVISITOR_DIR)/node_visitor.c
	$(CC) $(CFLAGS) $< -o $@

$(BUILD_DIR)/modifysql.o: $(MODIFYSQL_DIR)/modifysql.c
	$(CC) $(CFLAGS) -fPIC -c $(MODIFYSQL_DIR)/modifysql.c 

clean_demo_obj:
	rm -f $(BUILD_DIR)/*.o 
	
clean:
	rm -rf $(BUILD_DIR)/analyzescript 
	rm -f $(BUILD_DIR)/*.o 
